package pl.ydp.components.mathcell.mathrecognizer.geometry
{
	import flash.geom.Point;
	
	public class EuclideanVector
	{
		public function EuclideanVector(p1:Point, p2:Point)	{
			point = p1;
			
			length = Point.distance(p1, p2);
			
			angleRadians = Math.atan2(p2.y-p1.y, p2.x-p1.x);		
			angle = angleRadians*180/Math.PI;
			if (angle < 0){
				angle += 360;
			}
			
			
			var angle2:Number = angle + 360/16;
			
			if (angle2 > 360){
				angle2 -= 360;
			}
			/*
			//Math.floor(angle2 / 360 * 8);
			*/
			
			direction = VectorDirection.formAngle(angle);
			
			
			if (angle2 < 180){
				sense = 1;	
			} else {
				sense = -1;
			}
		}
		
		// PUBLIC FIELDS
				
		public var point:Point;
		public var direction:Number;
		public var sense:Number;
		public var angle:Number;
		public var angleRadians:Number;
		public var length:Number;
		
		// PUBLIC METHODS
		
		public function reverse():void{
			
			point = findEnd();
			
			direction = VectorDirection.getReversed(direction);
			
			if (sense == VectorSense.POSITIVE){
				sense = VectorSense.NEGATIVE;
			} else {
				sense = VectorSense.POSITIVE;
			}
			
			angle += 180;
			if (angle >= 360){
				angle -= 360;
			}
			angleRadians = angle/180*Math.PI;
		}
		
		public function findEnd():Point{
			return new Point(point.x + Math.cos(angleRadians)*length,point.y + Math.sin(angleRadians)*length); 	
		}

	}
}